<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :maskClosable="false"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange">
          <template slot="avatarslot" slot-scope="text, record, index">
            <div class="anty-img-wrap">
              <img :src="getAvatarView(record.status)"/>
            </div>
          </template>
        </a-table>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue,filterObj } from '@/utils/util'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  export default {
    name: "GlrLightPoleMemberRadioListAdd",
    mixins:[JeecgListMixin],
    components: { 
    },
    data () {
      return {
        disableMixinCreated:true,
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        paramLightPoleCode:"",
        paramDeviceType:0,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'名称',
            align:"center",
            dataIndex: 'name'
          }
        ],
        confirmLoading: false,
        validatorRules: {
          memberId: {rules: [
            {required: true, message: '请输入成员ID!'},
          ]},
          memberType: {rules: [
            {required: true, message: '请输入成员类型!'},
          ]},
          taskId: {rules: [
            {required: true, message: '请输入任务ID!'},
          ]},
          sysCompanyCode: {rules: [
          ]},
        },
        url: {
          list: "/glr/glrLightPoleDevice/lightPoleDeviceListAdd",
          bingPoleDevice:"/glr/glrLightPoleDevice/bingPoleDevice",
        }
      }
    },
    created () {
    },
    methods: {
      add (lightPoleCode,deviceType) {
        this.selectedRowKeys=[];
        this.paramLightPoleCode=lightPoleCode;
        this.paramDeviceType=deviceType;
        this.form.resetFields();
        this.visible = true;
        this.model.paramLightPoleCode=lightPoleCode;
        this.model.paramDeviceType=deviceType;

        this.queryParam.paramLightPoleCode = this.paramLightPoleCode;
        this.queryParam.paramDeviceType=this.paramDeviceType;
        this.ipagination.pageSize = 10;
        this.ipagination.pageSizeOptions = ['10','20', '60', '100'];

        this.loadData();
      },
      edit (record) {
        this.selectedRowKeys=[];
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'memberId','memberType','taskId','sysCompanyCode'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        var ids = "";
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          let httpurl = '';
          let method = '';
          httpurl += that.url.bingPoleDevice;
          method = 'post';
          httpAction(httpurl, {ids:ids,lightPoleCode:that.paramLightPoleCode,deviceType:that.paramDeviceType}, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'memberId','memberType','columnId','sysCompanyCode'))
      },
      getAvatarView: function (status) {
        if(status=='Y'){
          return   require('@/assets/img/zaixian.png');
        }else{
          return   require('@/assets/img/lixian.png');
        }
      }

      
    }
  }
</script>